package kmeansclustering;

import java.util.ArrayList;
import java.util.Iterator;

public class Point {
	public int id;
	
	public int cluster;
	public float[] property;
	public int label; // the last label of this Point
	
	public Point(float[] property, int id) {
		this.id = id;
		this.property = property;
	}
	
	public Point(int[] property, int id){
		this.id = id;
	}
		
	public double calculateEuclidDistance(Point point){
		double Sum = 0.0;
        for(int i=0;i<this.property.length;i++) {
           Sum = Sum + Math.pow((this.property[i] - point.property[i]),2.0);
        }
        return Math.sqrt(Sum);
	}
	
	public double squareCalculateEuclidDistance(Point point){
		double Sum = 0.0;
        for(int i=0;i<this.property.length;i++) {
           Sum = Sum + Math.pow((this.property[i] - point.property[i]),2.0);
        }
        return Sum;
	}
	
	//set cluster for point
	public int setCluster(ArrayList<Point> centroids){
		Iterator<Point> iterator = centroids.iterator();
		double minDistance = 0;
		int id = 0;
		while(iterator.hasNext()){
                    // Nen de binh phuong, va tan dung ket qua de tinh loi luon.
			double distance = calculateEuclidDistance(iterator.next());
			if (distance < minDistance){
				minDistance = distance;
				id = iterator.next().id;
			}
		}
		return id;
	}
}
